﻿#include <iostream>
#include <vector>
using namespace std;


class Solution
{
    bool vis[101][101];
    int _m, _n, _cnt;
    int ret = 0;
    int dx[4] = { 0,0,-1,1 };
    int dy[4] = { 1,-1,0,0 };
public:
    // LCR 130. 衣橱整理
    int wardrobeFinishing(int m, int n, int cnt)
    {
        _m = m, _n = n, _cnt = cnt;
        dfs(0, 0);
        return ret;
    }

    void dfs(int i, int j)
    {
        ret++;
        vis[i][j] = true;

        for (int k = 0; k < 4; k++)
        {
            int x = i + dx[k], y = j + dy[k];
            if (x >= 0 && x < _m && y >= 0 && y < _n && !vis[x][y] && check(x, y))
                dfs(x, y);
        }
    }

    bool check(int i, int j)
    {
        int tmp = 0;
        while (i)
        {
            tmp += i % 10;
            i /= 10;
        }
        while (j)
        {
            tmp += j % 10;
            j /= 10;
        }
        return tmp <= _cnt;
    }
};

int main()
{

    return 0;
}